home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EBKSRC.ARJ / EB3.HPP < prev    next >
C/C++ Source or Header  |  1991-07-30  |  5KB  |  229 lines

  1. /*
  2.  
  3.     eb3.hpp
  4.     7-30-91
  5.     Electronic Book: header for eb3.cpp
  6.  
  7.     Copyright 1991
  8.     John W. Small
  9.     All rights reserved
  10.  
  11.     PSW / Power SoftWare
  12.     P.O. Box 10072
  13.     McLean, Virginia 22102 8072 USA
  14.  
  15.     John Small
  16.     Voice: (703) 759-3838
  17.     CIS: 73757,2233
  18.  
  19. */
  20.  
  21.  
  22. #ifndef EB3_HPP
  23. #define EB3_HPP
  24.  
  25. #include <fstream.h>
  26. #include <dir.h>
  27.  
  28. #ifndef EBDEF_HPP
  29. #include <ebdef.hpp>
  30. #endif
  31.  
  32. #ifndef EB1_HPP
  33. #include <eb1.hpp>
  34. #endif
  35.  
  36. #ifndef EB2_HPP
  37. #include <eb2.hpp>
  38. #endif
  39.  
  40. #ifndef PICKLIST_HPP
  41. #include <picklist.hpp>
  42. #endif
  43.  
  44. #ifndef FLEXLIST_CPP
  45. #include <flexlist.hpp>
  46. #endif
  47.  
  48.  
  49. /*
  50.  
  51.     The HyperTopic class maintains a handle to the
  52.     topics in the file.  It is used to construct the
  53.     HyperContext class.  It's topic and clues can also
  54.     be read.
  55.  
  56. */
  57.  
  58. class HyperTopic {
  59.     char * inlinks;
  60.     long fpos;
  61.     unsigned contextLength;
  62.     char * outlinks;
  63.     #pragma argsused
  64.     void * operator new(size_t size)
  65.         { return (void *)0; }
  66. public:
  67.     HyperTopic(ifstream& f);
  68.     #pragma argsused
  69.     void * operator new(size_t size, void * ptr)
  70.         { return ptr; }
  71.     int ConstructOK()  { return contextLength; }
  72.     char * topic()  { return parseLinks(inlinks); }
  73.     char * clue() { return parseLinks(); }
  74.     int match(HyperTextTargeT HTT,
  75.         unsigned topicNum);
  76.     HyperContexT fetch(HyperTextTargeT HTT,
  77.         unsigned topicNum);
  78.     ~HyperTopic() { delete inlinks; delete outlinks; }
  79. };
  80. typedef HyperTopic *HyperTopiC;
  81. #define HyperTopiC0 ((HyperTopiC)0)
  82.  
  83.  
  84.  
  85. /*
  86.  
  87.     The PickTableOfContents class is used to build a
  88.     sequential list on topic entries.
  89.  
  90. */
  91.  
  92. class PickTableOfContents : PickListWindow  {
  93.     virtual void dressWindow()
  94.         { putTitle(" Table of Contents "); }
  95. public:
  96.     PickTableOfContents() : PickListWindow(0,PalettE0,
  97.         PalettE0,FLstrings,MAX_HYPER_TOC,FLcompare0)
  98.         {}
  99.     PickListWindow::choose;
  100.     char *choice() { return (char *)
  101.         PickListWindow::choice(); }
  102.     char *addT(char *T)  { return (char *) addD(T); }
  103. };
  104. typedef PickTableOfContents * PickTOC;
  105. #define PickTOC0 ((PickTOC)0)
  106.  
  107.  
  108.  
  109. /*
  110.  
  111.     The PickIndex class is used to build a sorted
  112.     PickListWindow of index entries.
  113.  
  114. */
  115.  
  116. class PickIndex : PickListWindow {
  117.     char buf[MAX_HYPER_LINE];
  118.     char * lastT;  // last topic added
  119.     virtual void dressWindow()
  120.         { putTitle(" Index "); }
  121. public:
  122.     PickIndex() : PickListWindow(0,PalettE0,
  123.         PalettE0,FLstrings,MAX_HYPER_IDX,
  124.         FLcomparE(stricmp))
  125.         { lastT = (char *)0; }
  126.     PickListWindow::choose;
  127.     char * choice();
  128.     // add topic
  129.     char *addT(char *T)
  130.         { return (lastT = (char *) addD(T)); }
  131.     // add clue for last topic added
  132.     char *addC(char *C)  { return (char *)
  133.         ((C && lastT)? addD(strcat(strcat
  134.             (strcpy(buf,C),
  135.             HYPER_LINKS_DELIMIT_STR),lastT))
  136.             :0); }
  137. };
  138. typedef PickIndex * PickIDX;
  139. #define PickIDX0 ((PickIDX)0)
  140.  
  141.  
  142.  
  143.  
  144. /*
  145.  
  146.     The HyperFile class is used to load a list of
  147.     HyperTopic handles to the topics in the file.
  148.     The context of a topic can be fetched.  The
  149.     class also maintains a reference count to
  150.     determine when it can be discarded.  A Table of
  151.     Contents or Index can also be generated for
  152.     the file.
  153.  
  154. */
  155.  
  156.  
  157. class HyperFile : FlexList /* of HyperTopics */  {
  158.     char fname[MAXPATH];
  159.     unsigned refs;
  160.     // A variant FlexList is used so that the
  161.     // HyperTopics class destructor can be called!
  162.     #pragma argsused
  163.     virtual FlexN FNnew(const void *D)  { return
  164.         (FlexN) new char[sizeof(FlexNode)-1
  165.         +sizeof(HyperTopic)]; }
  166.     #pragma argsused
  167.     virtual int   FNwrite(void *ND, const void *D)
  168.         { return 0; }
  169.     #pragma argsused
  170.     virtual int   FNread(const void *ND, void *D)
  171.         { return 0; }
  172.     virtual int   FNdestruct(void *ND, void *D);
  173.     #pragma argsused
  174.     void * operator new(size_t size)
  175.         { return (void *)0; }
  176. public:
  177.     HyperFile(const char *fname);
  178.     #pragma argsused
  179.     void * operator new(size_t size, void * ptr)
  180.         { return ptr; }
  181.     int ConstructOK() { return ((strlen(fname)
  182.         && Nodes())? 1 : 0); }
  183.     int match(HyperTextTargeT HTT);
  184.     HyperContexT fetch(HyperTextTargeT HTT);
  185.     int discard(const char *fname);
  186.     PickTOC TableOfContents(const char *fname);
  187.     PickIDX Index(const char *fname);
  188.     ~HyperFile() {}
  189. };
  190. typedef HyperFile * HyperFilE;
  191. #define HyperFilE0 ((HyperFilE)0)
  192.  
  193.  
  194. /*
  195.  
  196.     The HyperServer is a FlexList of HyperFile
  197.     FlexLists!  HyperTopics are loaded through
  198.     this interface by the HyperView class.
  199.  
  200. */
  201.  
  202. class HyperServer : FlexList /* of HyperFiles */ {
  203.     // A variant FlexList is used so that the
  204.     // HyperFile class destructor can be called!
  205.     #pragma argsused
  206.     virtual FlexN FNnew(const void *D)  { return
  207.         (FlexN) new char[sizeof(FlexNode)-1
  208.         +sizeof(HyperFile)]; }
  209.     #pragma argsused
  210.     virtual int   FNwrite(void *ND, const void *D)
  211.         { return 0; }
  212.     #pragma argsused
  213.     virtual int   FNread(const void *ND, void *D)
  214.         { return 0; }
  215.     virtual int   FNdestruct(void *ND, void *D);
  216. public:
  217.     HyperServer() : FlexList(FLvariantData) {}
  218.     HyperContexT fetch(HyperTextTargeT HTT);
  219.     void discard(const char *fname);
  220.     PickTOC TableOfContents(const char *fname);
  221.     PickIDX Index(const char *fname);
  222. };
  223. typedef HyperServer * HyperServeR;
  224. #define HyperServeR0 ((HyperServeR)0)
  225.  
  226.  
  227. #endif
  228.  
  229.